package judesart.app.util;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class BlobMigrationRecord {
	
	public static String getNewBlobKey(String oldBlobKey) {
		String newBlobKey = "";
		try {
			DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
			Key key = KeyFactory.createKey("__BlobMigration__", oldBlobKey);
			Entity blobkey = datastore.get(key);
			BlobKey blobKey = (BlobKey) blobkey.getProperty("new_blob_key");
			newBlobKey = blobKey.getKeyString();
		} catch (EntityNotFoundException e) {
			newBlobKey = oldBlobKey;
		}
		return newBlobKey;
	}

}
